package com.partsoft.dits.mq;

import java.util.Hashtable;

import org.springframework.beans.factory.InitializingBean;

import com.ibm.mq.MQC;
import com.ibm.mq.MQException;
import com.ibm.mq.MQQueueManager;

public class RemoteBindMQConnectFactory extends AbstractMQConnectFactory implements InitializingBean,
		MQConnectFactory {
	
	private String hostName;

	private int port = 1414;

	private String channelName = "SYSTEM.DEF.SVRCONN";

	private String userId = null;

	private String password = null;

	public void afterPropertiesSet() {
	}

	public MQQueueManager getQueueManager(String name) throws MQException {
		Hashtable<Object, Object> hashtable = new Hashtable<Object, Object>(7);
		hashtable.put(MQC.HOST_NAME_PROPERTY, getHostName());
		hashtable.put(MQC.PORT_PROPERTY, getPort());
		hashtable.put(MQC.CHANNEL_PROPERTY, getChannelName());
		if (getUserId() != null) {
			hashtable.put(MQC.USER_ID_PROPERTY, getUserId());
			hashtable.put(MQC.PASSWORD_PROPERTY, getPassword());
		}
		hashtable.put(MQC.CCSID_PROPERTY, getCCSID());
		hashtable.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
		return new MQQueueManager(name, hashtable);
	}

	public MQQueueManager getDefaultQueueManager() throws MQException {
		return getQueueManager(getDefaultQMName());
	}

	public String getHostName() {
		return hostName;
	}

	public void setHostName(String hostName) {
		this.hostName = hostName;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getChannelName() {
		return channelName;
	}

	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
}
